<template>
  <div class="Jurisdiction common">
    <div class="Jurisdiction-content">
      <!-- 搜索栏 -->
      <div class="search-group">
        <div class="dis-inline" style="width:80%">
          <el-input
            class="wid-15 mr10 ml10"
            placeholder="用户名"
            v-model="searchVal.username"
            size="small"
            clearable
          >
          </el-input>
          <el-date-picker
            class="wid-25 ml10"
            size="small"
            v-model="searchVal.dataVal"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
          >
          </el-date-picker>

          <el-select
            class="mr10 ml10"
            v-model="searchVal.status"
            clearable
            size="small"
            placeholder="状态"
          >
            <el-option
              v-for="item in statusList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>

          <el-select
            class="mr10 ml10"
            v-model="searchVal.role"
            clearable
            size="small"
            placeholder="角色"
          >
            <el-option
              v-for="item in roleList"
              :key="item.value"
              :label="item.value"
              :value="item.value"
            >
            </el-option>
          </el-select>

          <el-select
            class="mr10 ml10"
            v-model="searchVal.ed_user_grade"
            clearable
            size="small"
            placeholder="二代等级"
          >
            <el-option
              v-for="item in ed_user_grade"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <el-button
            class="new-btn"
            size="small"
            icon="el-icon-search"
            @click="searchFnc"
            >查询</el-button
          >
        </div>

        <el-button
          v-if="
            power_user && power_user.indexOf('api.user_user_resource_POST') > 0
          "
          class="fr new-btn mr10"
          @click="showAddDialog"
          icon="el-icon-plus"
          size="small"
          >新增</el-button
        >
      </div>

      <!-- 表格栏 -->
      <el-table :height="userAgent ? '' : '550'" :data="tableData" class="mt20" v-loading="loading">
        <el-table-column type="index" label="序号" align="center">
        </el-table-column>
        <el-table-column prop="username" label="用户名" align="center">
        </el-table-column>
        <el-table-column prop="cname" label="姓名" align="center">
        </el-table-column>
        <el-table-column prop="role" label="角色" align="center">
        </el-table-column>
        <el-table-column label="二代等级" align="center">
          <template slot-scope="scope">
            <div>
              {{ scope.row.grade}}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="block_name" label="部门" align="center">
          <template slot-scope="scope">
            <div>
              {{ scope.row.block_name?scope.row.block_name:'-'}}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="title_name" label="岗位" align="center">
          <template slot-scope="scope">
            <div>
              {{ scope.row.title_name?scope.row.title_name:'-'}}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="create_time_m" label="添加日期" align="center">
        </el-table-column>
        <el-table-column prop="cname" label="名称" align="center">
        </el-table-column>
        <el-table-column label="状态" align="center">
          <template slot-scope="scope">
            <div>
              {{ scope.row.status !== "停用" ? "启用中" : "停用中" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          width="300"
          prop="jurisdiction"
          label="操作"
          align="center"
        >
          <template slot-scope="scope">
            <div>
              <el-button
                type="primary"
                plain
                size="small"
                :disabled="scope.row.role === '二代'"
                v-show="
                  power_user.indexOf(
                    'api.user_privilege_user_privilege_resource_POST'
                  ) >= 0
                "
                @click="showPowerDialog(scope.row)"
                >权限修改</el-button
              >
              <el-button
                type="primary"
                plain
                size="small"
                v-show="
                  power_user.indexOf('api.user_user_resource_PUT') >= 0 ||
                    power_user.indexOf(
                      'api.user_contact_info_user_contact_info_resource_PUT'
                    ) >= 0 || userInfo.items[0].role === '商务助理'
                "
                @click="showEditDialog(scope.row)"
                >信息修改</el-button
              >
              <el-button
                :type="scope.row.status === '停用' ? 'success' : 'danger'"
                :disabled="scope.row.role === '超级管理员'"
                v-show="
                  power_user.indexOf(
                    'api.user_enable_user_enable_resource_PUT'
                  ) >= 0
                "
                @click="userEnable(scope.row)"
                plain
                size="small"
                >{{ scope.row.status === "停用" ? "启用" : "停用" }}</el-button
              >
            </div>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="block tac mt20">
        <el-pagination
          layout="total, prev, pager, next"
          @current-change="pageChange"
          :total="total"
        >
        </el-pagination>
      </div>

      <!-- 新增dialog -->
      <el-dialog :modal-append-to-body="false"  :top="userAgent ? '60px' : '15vh'" title="新增用户" :visible.sync="dialogVisible" width="50%" :close-on-click-modal="false">
        <el-form ref="form" :model="form" label-width="100px">
          <el-form-item label="用户名">
            <el-input v-model.trim="form.username" class="wid-90"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model.trim="form.password" class="wid-90"></el-input>
          </el-form-item>
           <el-form-item label="权限">
            <el-radio-group v-model="form.role">
              <el-radio label="管理员"></el-radio>
              <el-radio label="渠道"></el-radio>
              <el-radio label="运营"></el-radio>
              <el-radio label="二代"></el-radio>
              <el-radio label="KA"></el-radio>
              <el-radio label="SMB"></el-radio>
              <el-radio label="商务助理"></el-radio>
              <el-radio label="设计"></el-radio>
          </el-radio-group>
          </el-form-item>
          <el-form-item label="姓名">
            <el-input v-model="form.cname" class="wid-90"></el-input>
          </el-form-item>
          <el-form-item label="手机号">
            <el-input v-model="form.phone" class="wid-90"></el-input>
          </el-form-item>
          <el-form-item label="微信">
            <el-input v-model="form.wx" class="wid-90"></el-input>
          </el-form-item>
          <el-form-item label="邮箱">
            <el-input v-model="form.mail" class="wid-90"></el-input>
          </el-form-item>
          <el-form-item label="部门">
            <el-select v-for="(items,index ) in groupOptions" :clearable="index!==0?true:false" :key="index" @change="getGroupOptions(userOrga.userGroup[index],index+1, false)" v-model="userOrga.userGroup[index]" placeholder="" class="w20p mr25p">
              <el-option
                v-for="item in items"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                :disabled="item.disabled">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="岗位">
            <el-select v-model="userOrga.userJob" placeholder="岗位" class="wid-90" v-if="joboptions.length!==0" key="1">
              <el-option
                v-for="item in joboptions"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
            <el-button type="text" @click="linkToAddJob" v-else>暂时没有岗位,点此去新建{{form.role}}岗位?</el-button>
          </el-form-item>
          <el-form-item label="选择等级" v-show="form.role !=='SMB'">
            <el-select
              v-model="form.grade"
              class="wid-90"
              filterable
              placeholder="等级"
            >
              <el-option
                v-for="item in edGrade"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="分配运营" v-show="form.role==='KA' || form.role==='二代'">
            <el-select
              multiple
              v-model="form.yyName"
              class="wid-90"
              filterable
              placeholder="运营"
            >
              <el-option
                v-for="item in yyList"
                 :key="item.id"
                 :label="item.username + '-' + item.cname"
                 :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false" size="small"
            >取 消</el-button
          >
          <el-button type="primary" @click="addUser" size="small"
            >确 定</el-button
          >
        </span>
      </el-dialog>

      <!-- 修改dialog -->
      <el-dialog :modal-append-to-body="false" :top="userAgent ? '60px' : '15vh'" title="修改" :visible.sync="dialogVisible1" width="700px" center>
        <el-form  label-width="80px">
          <el-form-item  v-if="power_user.indexOf('api.user_user_resource_PUT') >= 0" label="密码修改">
            <el-input v-model="editForm.password" class="wid-78 fl mr10"></el-input>
            <el-button
            class="fl"
            type="primary"
            @click="editPassword"
            >确 定</el-button
          >
          </el-form-item>
          <el-form-item label="姓名">
            <el-input v-model="editInfo.cname" class="wid-90"></el-input>
          </el-form-item>
          <el-form-item label="权限">
            <el-radio-group v-model="editForm.role" disabled>
              <el-radio label="管理员"></el-radio>
              <el-radio label="渠道"></el-radio>
              <el-radio label="运营"></el-radio>
              <el-radio label="二代"></el-radio>
              <el-radio label="KA"></el-radio>
              <el-radio label="SMB"></el-radio>
              <el-radio label="设计"></el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="微信">
            <el-input v-model="editInfo.wx" class="wid-90"></el-input>
          </el-form-item>
          <el-form-item label="手机号">
            <el-input v-model="editInfo.phone" class="wid-90"></el-input>
          </el-form-item>
           <el-form-item label="邮箱">
            <el-input v-model="editInfo.mail" class="wid-90"></el-input>
          </el-form-item>
          <el-form-item label="部门">
            <el-select v-for="(items,index ) in groupOptions" :clearable="index!==0?true:false" :key="index" @change="getGroupOptions(userOrga.userGroup[index],index+1,false)" v-model="userOrga.userGroup[index]" placeholder="" class="w20p mr25p">
              <el-option
                v-for="item in items"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                :disabled="item.disabled">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="岗位">
            <el-select v-model="userOrga.userJob" placeholder="岗位" class="wid-90" v-if="joboptions.length!==0" key="2">
              <el-option
                v-for="item in joboptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                :disabled="item.disabled">
              </el-option>
            </el-select>
            <el-button type="text" @click="linkToAddJob" v-else>暂时没有岗位,点此去新建{{form.role}}岗位?</el-button>
          </el-form-item>
          <el-form-item label="分配运营" v-show="editForm.role==='KA' || editForm.role==='二代' || editForm.role==='SMB'">
            <el-select
              multiple
              v-model="editInfo.yyName"
              class="wid-90"
              filterable
              placeholder="运营"
            >
              <el-option
                v-for="item in yyList"
                 :key="item.id"
                 :label="item.username + '-' + item.cname"
                 :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="选择等级">
            <el-select
              v-model="editInfo.grade"
              class="wid-90"
              filterable
              placeholder="等级"
            >
              <el-option
                v-for="item in editGrade"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button
            class="mb10"
            type="primary"
            @click="dialogVisible1 = false"
            >取消</el-button
          >
          <el-button
            class="mb10"
            type="primary"
            @click="editInfoFnc"
            >确 定</el-button
          >
        </span>
      </el-dialog>

      <!-- 修改权限dialog -->
      <el-dialog :modal-append-to-body="false" :top="userAgent ? '60px' : '15vh'" title="修改权限" :visible.sync="dialogVisible2" width="60%" >
        <div>
          <el-transfer
            :titles="['未拥有权限', '已拥有权限']"
            v-model="value1"
            :data="power"
            filterable
          ></el-transfer>
          <span slot="footer" class="dialog-footer tac wid-100 dis-inline mt20">
            <el-button
              class="mb10 wid-30"
              type="primary"
              @click="editPower"
              size="small"
              >确 定</el-button
            >
          </span>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script>
export default {
  name: "userManage",
  data() {
    const generateData = _ => {
      const data = [];
      for (let i = 1; i <= 15; i++) {
        data.push({
          key: i,
          label: `备选项 ${i}`
        });
      }
      return data;
    };
    return {
      data: generateData(),
      value1: [195, 177],
      powerdata: "", // 权限数据中转
      loading: true, // 加载中
      tableData: [], // 表格数据
      searchVal: {
        dataVal: "", // 时间
        username: "", // 用户名
        ed_user_grade: "", // 二代等级
        status: "", // 是否停用
        role: "" // 角色
      }, // 查询
      dialogVisible: false, // 显示新增弹框dialog
      dialogVisible1: false, // 显示编辑弹框dialog
      dialogVisible2: false, // 显示权限弹框dialog
      total: 0, // 页码
      pageIndex: 1, // 页码
      form: {
        // 新增弹框数据
        role: "", // 角色
        username: "", // 用户名
        password: "", // 密码
        wx: "", // 微信
        phone: "", // 手机
        cname: "", // 名字
        mail: "", // 邮箱
        grade: "", // 等级
        user_id:'', // user_id
        block_id:'', // 区块id
        yyName: [] // 运营的名字
      },
      userOrga: {
        userJob:'',
        //下拉框绑定的值
        userGroup:[],
      },
      yyList: [], //运营数组
      editForm: {
        // 修改弹框数据
        username: "",
        role: "",
        password: "",
        id: ""
      },
      edGrade: [
        {
          value: "1",
          label: "等级一"
        },
        {
          value: "2",
          label: "等级二"
        },
        {
          value: "3",
          label: "等级三"
        },
        {
          value: "4",
          label: "等级四"
        }
      ],
      statusList: [
        {
          value: "停用",
          label: "停用"
        }
      ],
      editGrade: [
        {
          value: "1",
          label: "等级一"
        },
        {
          value: "2",
          label: "等级二"
        },
        {
          value: "3",
          label: "等级三"
        },
        {
          value: "4",
          label: "等级四"
        }
      ],
      editInfo: {
        cname: "",
        grade: "",
        mail: "",
        phone: "",
        user_id: "",
        wx: "",
        yyName:""
      },
      joboptions: [], // 岗位数据
      groupOptions: [],// 部门数据
      allBlockList:[], //存储请求到的所有区块信息
      tempJobList: []
    };
  },
  methods: {
    // 显示权限弹框
    showPowerDialog(r) {
      let self = this;
      this.powerdata = r;
      this.$api
        .getUserPrivilege({
          params: {
            user_id: r.id
          }
        })
        .then(res => {
          self.value1 = res.items.map(o => {
            return o.ep_privilege_id;
          });
        });
      this.dialogVisible2 = true;
    },
    // 修改权限方法
    editPower() {
      this.$confirm("确认修改该用户权限?").then(() => {
        this.$api
          .editUserPrivilege({
            user_id: this.powerdata.id,
            privilege_id_list: this.value1
          })
          .then(res => {
            if (Number(res.err_no) === 0) {
              this.$notify({
                title: "提示",
                message: "更新成功",
                type: "success"
              });
              this.dialogVisible2 = false;
            } else {
              this.$notify({
                title: "提示",
                message: "更新失败",
                type: "error"
              });
            }
          });
      });
    },
    // 显示新增弹框
    showAddDialog() {
      this.groupOptions = this.groupOptions.slice(0,1);
      // 常规数据
      this.form = {
        role: "",
        username: "",
        password: "",
        cname: "",
        wx: "",
        phone: "",
        mail: "",
        grade: ""
      };
      // 部门数据
      this.userOrga = {
        userJob:'',
        //下拉框绑定的值
        userGroup:[]
      };
      this.dialogVisible = true;
    },
    searchFnc() {
      this.pageIndex = 1
      this.getUserList();
    },
    // 页码改变
    pageChange(r) {
      this.pageIndex = r;
      this.getUserList();
    },
    showEditDialog(row) {
      this.editForm = {
        id: row.id,
        password: "",
        role: row.role
      };
      // 编辑的信息
      this.editInfo = {
        cname: row.cname,
        grade: String(row.grade),
        mail: row.mail,
        phone: row.phone,
        wx: row.wx,
        user_id: row.id,
        yyName: row.yy_user_id ? row.yy_user_id.split(',') : []
      };
      this.editInfo.yyName =   this.editInfo.yyName.map(ele=>{return Number(ele);})
      // 岗位信息
      this.userOrga = {
        userJob: row.title_id?row.title_id :'',
        userGroup:[],
      };
      // 绑定组织架构数据
      this.form = {
        user_id: row.id
      }
      this.tempJobList = [];
      this.getLastJob(row.block_id)
      this.dialogVisible1 = true;
    },
    linkToAddJob(){
      this.$router.push('/jobsmanage');
    },
    // 获取用户
    getUserList() {
      this.loading = true;
      this.$api
        .getUser({
          params: {
            per_page: 10,
            page: this.pageIndex,
            username: this.searchVal.username,
            ed_user_grade: this.searchVal.ed_user_grade,
            status: this.searchVal.status,
            role: this.searchVal.role,
            create_time_start: this.searchVal.dataVal
              ? this.searchVal.dataVal[0]
              : "",
            create_time_end: this.searchVal.dataVal
              ? this.searchVal.dataVal[1]
              : ""
          }
        })
        .then(res => {
          this.tableData = res.items;
          this.total = res.count;
          this.loading = false;
        });
    },
    // 增加用户
    addUser() {
      if(this.form.role === 'SMB'){
        this.form.grade = '1'
      }
      if(this.form.role!=='二代'&&
          (!this.userOrga.userJob||
          this.userOrga.userGroup.length===0)){
          this.$notify({
            title: "警告",
            message: "岗位或部门信息不能为空哦",
            type: "warning"
          });
          return false;
      }
      if (Object.values(this.form).includes("")) {
        this.$notify({
          title: "警告",
          message: "创建用户信息不能为空",
          type: "warning"
        });
        return false;
      } else if (this.form.password.length < 6) {
        this.$notify({
          title: "警告",
          message: "密码长度不能低于6位",
          type: "warning"
        });
        return false;
      }
      this.form.grade = Number(this.form.grade);
      if (this.form.role==='KA' || this.form.role==='二代') {
        if (this.form.yyName.length===0) {
          this.$notify({
            title: "警告",
            message: "请选择运营",
            type: "warning"
          });
          return false;
        }
      }
      this.$api
        .createUser(this.form)
        .then(res => {
          if (Number(res.err_no) === 0) {
            this.$notify({
              title: "成功",
              message: `新增用户成功`,
              type: "success"
            });
            this.form.block_id = this.userOrga.userGroup[this.userOrga.userGroup.length-1]?this.userOrga.userGroup[this.userOrga.userGroup.length-1]:'';
            this.form.user_id = res.data.user_id;
            if(this.form.block_id&&this.userOrga.userJob){
              this.bindTogroup();
            }
            this.dialogVisible = false;

            if(this.form.role==='KA'){
              let f = {
                status: '审核通过'
              }
              f.yy_user_id_list = this.form.yyName ? (this.form.yyName.map(item => String(item))).join(","):''
              f.user_id = res.data.user_id
              f.status_remark = ''
              this.$api.updateStatus(f).then(res => {});
            }
            this.getUserList();
          } else {
            this.$notify({
              title: "失败",
              message: `${res.err_message}`,
              type: "error"
            });
          }
        })
        .catch(() => {
          // 应该不能删除自己 后台做判断
          this.$notify({
            title: "错误",
            message: "创建用户失败",
            type: "error"
          });
        });
    },
    //绑定到组织架构
    bindTogroup(){
      this.$api.bindToGroup({
        title_id: this.userOrga.userJob,
        user_id: this.form.user_id,
        block_id: this.form.block_id
      }).then(res=>{
        this.dialogVisible = false;
        if(res.err_no===0){
           this.$notify({
            title: "成功",
            message: "绑定部门成员成功",
            type: "success"
          });
        }
        this.getUserList();
      })
      .catch(err=>{})
    },
    // 删除用户
    deleteUser(row) {
      this.$confirm(`删除${row.username}用户数据将全部清空，确认删除?`).then(
        () => {
          this.$api
            .deleteUser({
              data: {
                user_id: row.id
              }
            })
            .then(res => {
              if (Number(res.err_no) === 0) {
                this.$notify({
                  title: "成功",
                  message: `删除${row.username}用户成功`,
                  type: "success"
                });
                this.getUserList();
              } else {
                this.$notify({
                  title: "失败",
                  message: res.err_message,
                  type: "error"
                });
              }
            });
        }
      );
    },
    // 修改密码
    editPassword() {
      if (!this.editForm.password || this.editForm.password.length < 6) {
        this.$notify({
          title: "警告",
          message: "密码不能为空且长度不能小于6位",
          type: "warning"
        });
        return false;
      }
      this.$confirm(`确认修改账户${this.editForm.username}的密码？`).then(
        () => {
          this.$api
            .updateUser({
              user_id: this.editForm.id,
              password: this.editForm.password
            })
            .then(() => {
              this.$notify({
                message: "密码修改成功",
                type: "success"
              });
              this.getUserList();
              this.dialogVisible1 = false;
            })
            .catch(() => {
              this.$notify({
                message: "密码修改失败",
                type: "error"
              });
            });
        }
      );
    },
    // 启用或者停用
    userEnable(row) {
      this.$confirm(
        `确认${row.status === "停用" ? "启用" : "停用"}该用户`
      ).then(() => {
        this.$api
          .userEnable({
            enable: row.status === "停用" ? true : false,
            user_id: Number(row.id)
          })
          .then(res => {
            if (Number(res.err_no) === 0) {
              this.$notify({
                title: "提示",
                message: `${row.status === "停用" ? "启用" : "停用"}成功`,
                type: "success"
              });
            } else {
              this.$notify({
                title: "提示",
                message: res.err_message,
                type: "error"
              });
            }
            this.getUserList();
          })
          .catch(() => {
            this.$notify({
              title: "提示",
              message: `${row.status === "停用" ? "启用" : "停用"}失败`,
              type: "error"
            });
          });
      });
    },
    editInfoFnc() {
      if(this.editForm.role!=='二代'&&(!this.userOrga.userJob||this.userOrga.userGroup.length===0)){
        this.$notify({
          title: "警告",
          message: "请确保岗位或者部门不为空",
          type: "warning"
        });
        return;
      }

      this.editInfo.grade = Number(this.editInfo.grade);
      this.form.block_id = this.userOrga.userGroup[this.userOrga.userGroup.length-1];
      this.$confirm("确认修改用户信息?").then(() => {
        this.$api.userContactInfo(this.editInfo).then(res => {
          if (Number(res.err_no) === 0) {
            this.getUserList();
          } else {
            console.log("更新失败");
          }
          this.dialogVisible1 = false;
        });
        if(this.form.block_id&&this.userOrga.userJob){
          this.bindTogroup();
        }
        if(this.editForm.role==='KA'||this.editForm.role==='二代'){
          let f = {
            status: '审核通过'
          }
          f.yy_user_id_list = (this.editInfo.yyName.map(item => String(item))).join(",")
          f.user_id =  this.editForm.id
          f.status_remark = ''
          this.$api.updateStatus(f).then(res => {});
        }
      });
    },
    // 获取所有岗位
    getAllJobs(){
      this.$api.getAllJobsTitle({
        params:{
          per_page: 1000000
        }
      }).then(res => {
        this.joboptions = res.items
      })
      .catch(err =>{})
    },
    // 获取所有区块
    getAllBlocks(){
      this.$api.getAllBlocks().then(res => {
        this.allBlockList = res.items;
        this.groupOptions[0] = res.items.filter(o=>{
          return o.parent_id === null
        })
      })
      .catch(err => {
        throw(err)
      })
    },
    // smb下拉框选择区域
    getGroupOptions(parent_id,optionIndex,status){
      this.groupOptions[optionIndex] = this.allBlockList.filter(o=>{
        return o.parent_id===parent_id
      })
      if(!status){
        if(parent_id==="") optionIndex = optionIndex - 1;
        this.userOrga.userGroup = this.userOrga.userGroup.slice(0,optionIndex);
      }
      if(this.groupOptions[optionIndex].length==0){
        this.groupOptions = this.groupOptions.slice(0,optionIndex);
        return;
      }
    },
    getYyList(){
      this.$api
      .getUser({
        params: {
          role: "运营",
          ignore_my_role: 1,
          per_page: 10000000
        }
      })
      .then(res => {
        this.yyList = res.items;
      });
    },
    getLastJob(id){
      this.allBlockList.forEach(ele=>{
        if(ele.id === id){
          this.tempJobList.push(Number(ele.id));
          this.userOrga.userGroup.push(ele.id);
          if(ele.parent_id){
            let tempId = ele.parent_id;
            this.getLastJob(tempId);
          }else{
            this.userOrga.userGroup.reverse();
            this.tempJobList.push(null);
            this.tempJobList.reverse()
            if(this.tempJobList.length<=1) return;
            this.tempJobList.forEach((ele, index)=>{
              this.getGroupOptions(ele,index,true)
            })
          }
        }
      })
    }
  },
  created() {
    this.getUserList();
    this.getAllJobs();
    this.getAllBlocks();
    this.getYyList();
  }
};
</script>
<style lang="stylus" scoped>
.w20p
  width 21%
.mr25p
  margin-right 1%
</style>
